<template>
	<view class="notice_details">
		<base-navbar back-color="#fff" :title="detail.title"></base-navbar>
		<view class="u-content">
			<!-- #ifdef H5 || APP -->
			<!-- <h3>{{ detail.title }}</h3> -->
			<view v-html="detail.content"></view>
			<!-- #endif -->
			<!-- #ifdef MP -->
			<!-- <view class="u-title">{{ detail.title }}</view> -->
			<rich-text :nodes="detail.content"></rich-text>
			<!-- #endif -->
		</view>
	</view>
</template>

<script setup>
	import request from '@/utils/request';
	import checkLogin from '@/utils/login';
	import {
		ref,
		reactive,
		toRefs,
		inject
	} from 'vue';
	import {
		onLoad,
		onShow,
		onPullDownRefresh,
		onReachBottom,
	} from '@dcloudio/uni-app';

	const state = reactive({
		id: 0,
		detail: {},
	});

	onLoad((opt) => {
		if (opt.hasOwnProperty('id')) {
			state.id = opt.id;
		}
	});

	onShow(() => {
		//登录过期自动登录
		if (!checkLogin()) {
			pageRoute('/pages/users/login/login');
		} else {
			getNoticeDetail();
		}
	});

	onPullDownRefresh((e) => {
		console.log("下拉刷新", e);
	});

	onReachBottom((e) => {
		console.log("上拉加载更多", e);
	});

	function getNoticeDetail() {
		request.get('content/getNoticeInfo', {
			id: state.id,
		}).then(res => {
			state.detail = res.data;
			addRead();
		})
	}

	function addRead() {
		request.post('content/addReadNotice', {
			id: state.id,
		}).then(res => {
			console.log('已读', res);
		})
	}

	function pageRoute(url) {
		uni.navigateTo({
			url
		});
	};

	function pageTabRoute(url) {
		uni.switchTab({
			url
		});
	};

	const {
		id,
		detail,
	} = toRefs(state);
</script>

<style lang="scss">
	.notice_details {
		padding: 24rpx 24rpx;
		box-sizing: border-box;

		.u-content {
			padding: 20rpx;
			background-color: white;

			h3 {
				text-align: center;
				margin-bottom: 24prx;
			}
		}

		.u-title {
			display: block;
			text-align: center;
			font-size: 1.17em;
			margin-bottom: 24prx;
			font-weight: bold;
			unicode-bidi: isolate;
		}
	}
</style>